﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.ListProductViewModels>" %>

<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Thống kê</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript" src="/ThemeExtends/AdminSkin/js/jquery.flot.js"></script>
    <script type="text/javascript" src="/ThemeExtends/AdminSkin/js/jquery.flot.stack.js"></script>	
    <link href="../../Content/popup.css" rel="stylesheet" type="text/css" />

  <% 
     int? ProductID = null;
     int? status = 1;
     DateTime? EndDate = null;
     //BaseController baseFont = new BaseController();
     int site = 7;
     int languageId =1 ;//StockModel.GetLanguageIDByCountryCode(baseFont.DefaultLanguageGetter());
     string call=Request.QueryString["call"]==null?"":Request.QueryString["call"];
     string GetproID = Request.QueryString["id"] == null ? "" : Request.QueryString["id"];
     string GetSerialThe = Request.QueryString["serial"] == null ? "" : Request.QueryString["serial"];
     string GetUrlEditStock="/7/vi/Stock/EditStock/";
      %> 

<script type="text/javascript" language="javascript">
    function PostRequest() 
    {
        var getProductID = document.getElementById("ListProduct").value;
        var stringCall = document.getElementById("stringCall").value;
        var site = document.getElementById("site").value;
        var txtSerialThe = document.getElementById("txtSerialThe").value;
        if (stringCall == "") {

        }
        else {
            document.location.href = "/7/vi/HomeMaster/BusinessStatistics?call=" + stringCall + "&id=" + getProductID + "&serial=" + txtSerialThe;
        }
    }


</script>

   <!--Popup-->
    <%--<script language="javascript" src="/Scripts/modaljquery.js"></script>
    <script language="javascript" src="/Scripts/modal.popup.js"></script>--%>
       <script type="text/javascript">

           function GetItemThe(id)
           {
             
               var ids = id;
               $.ajax
               ({
                   url: '<%=Url.Action("GetProductStockDetailByID","Stock")%>',
                   data: { ids: ids },
                   type: "POST",
                   traditional: true,
                   success: function (result) {
                       $('#txtProductStockDetailID').val(result.split("|")[0]);
                       $('#txtSerial').val(result.split("|")[1]);
                       $('#txtCode').val(result.split("|")[2]);
                       $('#txtEndDate').val(result.split("|")[3]);
                       document.getElementById("ddlStatus").value = (result.split("|")[4]);
                       document.getElementById("popup_name").style.display = "block";
                   }
                   
               });
           }
           function EditSaveItems() 
           {
               var ProductStockDetailID = document.getElementById("txtProductStockDetailID").value;
               var Serial = document.getElementById("txtSerial").value;
               var EndDate = document.getElementById("txtEndDate").value;
               var Status = document.getElementById("ddlStatus").value;
               var Code = document.getElementById("txtCode").value;

               var ids = [ProductStockDetailID, Serial, EndDate, Status, Code];
               $.ajax
               ({
                   url: '<%=Url.Action("SaveEditProductStockDetailItem","Stock")%>',
                   data: { ids: ids },
                   type: "POST",
                   traditional: true,
                   success: function (data) 
                   {
                       document.getElementById("popup_name").style.display = "none";
                   }
              });
               alert("Sửa thành công!");
               document.location.reload(true);

           }
    
    </script>
   <!--Popup-->
<script type="text/javascript" language="javascript">
        function SetDate(id) {
            $("#txtEndDate").datepicker({ dateFormat: 'dd/mm/yy' });
        }
</script>
<% using (Html.BeginForm("BusinessStatistics", "HomeMaster", FormMethod.Post, new { id = "sendFileForm", enctype = "multipart/form-data" }))
   {%>
    <div class="clear"></div>
   
    <div class="column full">
    <div class="box ">
         <%=Html.Hidden("stringCall",call) %>
         <%=Html.Hidden("site", site)%>
         <%=Html.Hidden("txtProductStockDetailID")%>
		<h2 class="box-header">Thống kê</h2>
		<div class="box-content">

                    <div id="grid">
                        <style type="text/css">
                            #thongke a{font-size:13px; color: Blue;}
                            #thongke a:hover{border-bottom: 1px solid blue;color:Red;}
                            #thongke a:selected{color:Green;font-size:13px; font-weight:bold;}
                            #thongke a:active{color:Green;font-size:13px; font-weight:bold;}
                            #thongke a:visited{color:Green;font-size:13px; font-weight:bold;}
                        </style>
                                 <div id="thongke">

                                 <span><b>Thông kê cả quá trình doanh:</b></span><br />
<%--                                 <spa><a href="?call=dex">Tổng số lượng thẻ đã bán:<%=StockModel.GetOrder_ItemByProductID_Status(null,1)%></a></span><br />
                                 <span><a href="?call=unsold">Tổng Số lượng thẻ chưa bán:<%=StockModel.GetCountProduct_Stock_DetailByProductIDStatus(null,1,null)%> </a></span><br />
                                 <span><a href="?call=expired">Tổng Số lượng thẻ hết hạn:<%=StockModel.GetCountProduct_Stock_DetailByProductIDStatus(null,1,DateTime.Now) %> </a></span><br />--%>

                                
                                 <%if (string.IsNullOrEmpty(call))
                                   { %>
                                    </div>	    						               
				                 	<table class="display" id="tabledata" >
                                <thead>
					                <tr>
						               			               
						                <th>
							                <a href="#" class="<%= StockController.GetGridThClass(ViewData, "ProductName") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "ProductName")%>">
								               Tên Sản phẩm</a>
						                </th>
						
						                <th>
							                <a href="#" class="<%= StockController.GetGridThClass(ViewData, "ProductCode") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "ProductCode")%>">
								               Mã sản phẩm</a>
						                </th>											                

                                      
                                        
                                        <th>
                                            Giá sản phẩm
                                        </th>
                                        <th>
                                            Hàng đã bán
                                        </th> 
                                        <th>
                                            hàng hết hạn
                                        </th>                                     
                                        <th>
                                            Số lượng tồn kho
                                        </th>
                                        <th>
                                            Tổng sản phẩm trong kho</th>
                                   
					                </tr>
                          
                                </thead>
                                <% if (Model.ProductItem.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="9">
                                                Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% }
                                   else
                                   { %>
                                <tbody>
					                <% foreach (var item in Model.ProductItem)
                                    { %>
				    
						                <tr>						                
                                           

							                <td>
								                <%= item.ProductName%>
							                </td>
							
							                <td>
								                <%= item.ProductCode%>
							                </td>
												<%
                                            var arr = this.Request.Url.PathAndQuery.Split('/');
                                            int LanguageID = StockModel.GetLanguageIDByCountryCode(arr[2]);
                                            int siteGuid = int.Parse(arr[1]);
                                                     %>		                
                                            <%--<td>
                                                
                                                <%= Html.DropDownList("TypeProperties", new SelectList(StockModel.GetListTypePropertyByProduct(item.ProductID, -1,1), "TypePropertiesID", "TypePropertiesName"), "--Property--", new { onchange = "GotoProperty(this,"+item.ProductID+","+siteGuid+",'"+arr[2]+"');" })%>
                                                <br />
                                                <%= Html.ActionLink("Property manage", "ProductTypeProperties", new { id = item.ProductID })%>
                                            </td>--%>

                                            <%
                            string stockValue = "";
                            long stock = StockModel.GetProductStockByProductId(item.ProductID);
                            int? QuantityProduct = StockModel.GetOrder_ItemByProductID_Status(item.ProductID, 1); // status=1 là trạng thái đã thành toán toán trong hóa đơn 
                            if (stock != null)
                            {
                                if (stock == 0)
                                {
                                    stockValue = "Hết hàng";
                                }
                                else if (stock > 0)
                                {
                                    stockValue = "" + stock + "";

                                }
                            }
                            else
                            {
                                stockValue = "Nhập hàng";
                            }

    
                                                   
                                                %>
                                                
                                             <td>
                                                <% var prices = StockModel.GetLastProductPriceByProductId(item.ProductID, LanguageID, null) == null ? null : (StockModel.GetLastProductPriceByProductId(item.ProductID, LanguageID, null).PriceValue);
                                                   string price = "";
                                                   if (prices == null)
                                                   {
                                                       price = "Chưa có giá";
                                                   }
                                                   else
                                                   {
                                                       price = prices.ToString() + " VND";
                                                   }
                                                   %>
                                                <%= price%>
                                            </td>
                                            <td> 
                                            
                                            <a href="?call=dex&id=<%= item.ProductID %>" title="Chi tiết"><%= (int)(QuantityProduct == null ? 0 : QuantityProduct)%><br />
                                            </a>
                                            </td>
                                            <td> 
                                              <a href="?call=expired&id=<%= item.ProductID %>" title="Chi tiết"> <%=StockModel.GetCountProduct_Stock_DetailByProductIDStatus(item.ProductID, 1, DateTime.Now)%> <br />
                                              </a>
                                            </td>
                                            <td>
                                             <a href="?call=unsold&id=<%= item.ProductID %>" title="Chi tiết"><%=((int)stock - (int)(QuantityProduct == null ? 0 : QuantityProduct))%><br /></a>
                                            </td>
                                            <td>
                                                <%= Html.ActionLink(stockValue, "BusinessStatistics", new { id = item.ProductID })%><br />  
                                            </td>
                                         
						                </tr>
				    
					                <% } %>
					            </tbody>
                                <% } %>
				                </table>
			                <!-- data -->
                                  <%--<% if (Model.ProductItem.Count() > 0)
                                    { 
                                         %>
			                           <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                          <% } %>--%>

                                  <%}%>
                                   <%
                                   if(call=="unsold")
                                   { %>
                                   <div style="width:100%;text-align:center"><h4>THỐNG KÊ SỐ LƯỢNG THẺ CHƯA BÁN</h4></div>
                                  <table class="display" id="tabledata">
                                <thead>
					                <tr>

						
						                <th> Tên mã thẻ  </th>
                                        <th> Serial thẻ</th>											                
                                        <th> Code</th>	
                                        <th> Ngày hết hạn</th> 
                                        <th> Hành động</th>
					                </tr>
                               
                                  
                                </thead>
                                <%
                                       if (!string.IsNullOrEmpty(GetproID))
                                       {
                                           ProductID = int.Parse(GetproID);
                                       }
                                       
                                    //int? status=1;
                                    //DateTime? EndDate=null;
                                    SCSService.ProductService list = new SCSService.ProductService();
                                    var ListProductStockDetail = list.GetListProduct_Stock_DetailByProductIDStatus(ProductID, status, EndDate, GetSerialThe);
                                     %>
                                <% if (ListProductStockDetail.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="9">
                                                Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% }
                                   else
                                   { %>
                                <tbody>
					               <% foreach (var itemProductDetail in ListProductStockDetail)
                                   { %>
				    
						                <tr>						                
							                <td>
								            <%= itemProductDetail.ProductStockDetailID%>
							                </td>	                                                    
                                            <td>
                                             <%=itemProductDetail.Serial%>
                                            </td>
                                            <td>
                                             <%=StockModel.Decrypt(itemProductDetail.Code)%>
                                            </td>
                                         <%--   <td> 
                                              <%=String.Format("{0:MM/dd/yyyy}", itemProductDetail.EndDate)%>
                                            </td>--%>
                                            <td>                         
                                             <%--<a href="#?w=600" rel="popup_name" class="poplight" onclick="GetItemThe(<%= itemProductDetail.ProductStockDetailID%>);">Sửa</a>  --%>
                                             <a class="button white" href="#" onclick="GetItemThe(<%= itemProductDetail.ProductStockDetailID%>);"><span class="icon_single edit"></span></a>
                                       
                                            </td>        
						                </tr>
					             <% } %>
					            
                               
                                </tbody>
                                <% } %>
				               </table>
                                  <%} %>

                                   <%
                                    if (call == "expired")
                                   { %>
                                    <div style="width:100%;text-align:center"><h4>THỐNG KÊ SỐ LƯỢNG THẺ ĐÃ QUÁ HẠN</h4> </div>
                               
                                   <table class="display" id="tabledata">
                                <thead>
					                <tr>
						            
						
						                <th>
							                Tên mã thẻ
						                </th>											                
                                        <th>
							                Serial thẻ
						                </th>
                                        <th>
                                            Code
                                        </th>
                                        <th>
                                            Ngày hết hạn
                                        </th> 
                                        <th>
                                        Hành động
                                        </th>                                 
                                      
                               
					                </tr>
                               
                                  
                                </thead>
                                <%
                                   
                                   if (!string.IsNullOrEmpty(GetproID))
                                    {
                                    ProductID=int.Parse(GetproID);
                                    }
                                    EndDate=DateTime.Now;
                                    SCSService.ProductService list = new SCSService.ProductService();
                                    var ListProductStockDetail = list.GetListProduct_Stock_DetailByProductIDStatus(ProductID, status, EndDate, GetSerialThe);
                                     %>
                                <% if (ListProductStockDetail.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="9">
                                                Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% }
                                   else
                                   { %>
                                <tbody>
					           <% foreach (var itemProductDetail in ListProductStockDetail)
                                { %>
				    
						        <tr>						                
							        <td>
								    <%= itemProductDetail.ProductStockDetailID%>
							        </td>
                                    <td>
                                     <%=itemProductDetail.Serial%>
                                    </td>
                                    <td>
                                             <%=StockModel.Decrypt(itemProductDetail.Code)%>
                                    </td>
                                  <%--  <td> 
                                       <%=String.Format("{0:MM/dd/yyyy}", itemProductDetail.EndDate)%>
                                    </td>--%>
                                    <td>
                                    <%--<a href="#?w=600" rel="popup_name" class="poplight" onclick="GetItemThe(<%= itemProductDetail.ProductStockDetailID%>);">Sửa</a> --%>
                                     <a class="button white" href="#" onclick="GetItemThe(<%= itemProductDetail.ProductStockDetailID%>);"><span class="icon_single edit"></span></a>
                                    </td>
                                         
						                </tr>
				    
					                <% } %>
					            </tbody>
                                <% } %>
				                </table>
                                  <%} %>
		                
		                            <%
                                    if (call == "dex")
                                   { %>
                                    <div style="width:100%;text-align:center"><h4>THÔNG KÊ SỐ LƯỢNG THẺ ĐÃ BÁN</h4></div>
                                   <table class="display" id="tabledata">
                                <thead>
					                <tr>
						            
						
						                <th>
							                Tên mã thẻ
						                </th>											                
                                        <th>
							                Serial thẻ
						                </th>
                                         <th>
                                            Code
                                        </th>
                                        <th>
                                            Ngày hết hạn
                                        </th> 
                                       <th>Hành động</th>                                   
                                      
                               
					                </tr>
                               
                                  
                                </thead>
                                <%
                                   
                                   if (!string.IsNullOrEmpty(GetproID))
                                    {
                                    ProductID=int.Parse(GetproID);
                                    }
                                    EndDate=DateTime.Now;
                                    SCSService.ProductService list = new SCSService.ProductService();
                                    var ListProductStockDetail = list.GetListProduct_Stock_DetailByProductIDStatus(ProductID, 3, null, GetSerialThe);
                                     %>
                                <% if (ListProductStockDetail.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="9">
                                                Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% }
                                   else
                                   { %>
                                <tbody>
					           <% foreach (var itemProductDetail in ListProductStockDetail)
                                { %>
				    
						        <tr>						                
							        <td>
								    <%= itemProductDetail.ProductStockDetailID%>
							        </td>
                                    <td>
                                     <%=itemProductDetail.Serial%>
                                    </td>
                                    <td>
                                             <%=StockModel.Decrypt(itemProductDetail.Code)%>
                                    </td>
                                   <%-- <td> 
                                      <%=String.Format("{0:MM/dd/yyyy}", itemProductDetail.EndDate)%>
                                    </td>--%>
                                     <td>
                                      <%--<a href="#?w=600" rel="popup_name" class="poplight" onclick="GetItemThe(<%= itemProductDetail.ProductStockDetailID%>);">Sửa</a> --%>
                                      <a class="button white" href="#" onclick="GetItemThe(<%= itemProductDetail.ProductStockDetailID%>);"><span class="icon_single edit"></span></a>
                                    </td>
						                </tr>
				    
					                <% } %>
					            </tbody>
                                <% } %>
				                </table>
                                  <%} %>
		                




	                </div>  <!-- grid -->	
                
               
	</div>
              
         <div id="popup_name" style="display:none; position:absolute;width:894px; top:254px;height:159px; left:251px;right:inherit; background-color:rgba(71, 71, 71, 0.94);" >                                
                            <div id="TemplateTable" style="margin-top:12px;margin-right:41px;margin-left:41px;" >
                            <div style="width:100%; text-align:center; color:White;"><h4>SỬA THÔNG TIN THẺ</h4></div>
                            <table class="display">
                                <thead>
					                <tr>
						            						
						                <th>
							                Serial thẻ
						                </th>
                                        <th>
							                Code thẻ
						                </th>												                
                                        <th>
							                Ngày hết hạn
						                </th>
                                        <th>
                                            Trạng thái
                                        </th> 
					                </tr> 
                                </thead>
                 		                                    
						        <tr>						                
							       
                                    <td>
                                        <input type="text" id="txtSerial" class = "form-field small" style="width:180px;"/>
                                    </td>
                                     <td>
                                        <input type="text" id="txtCode" class = "form-field small" style="width:180px; "/>
                                    </td>
                                    <td>
								        <input type="text" id="txtEndDate" class = "form-field datepicker" style="width:180px;"/>
							        </td>
                                    <td>
                                         <%
                                                List<SelectListItem> Status = new List<SelectListItem>();
                                                Status.AddRange(new SelectListItem[] { 
                                                new SelectListItem{ Text = "Tất cả", Value = "" },
                                                new SelectListItem{ Text = "Thẻ chưa bán", Value = "1" },
                                                new SelectListItem{ Text = "Đã thanh toán", Value = "3" },
                                                new SelectListItem{ Text = "Thẻ hết hạn", Value = "2" }
                                                });
                                         %>
                                         <%=Html.DropDownList("ddlStatus", Status, new { @Style="width:180px;"})%> 
                                       
                                    </td>
                                     
						        </tr>
                                
                                    
                                

				                </table>
                                <div style="margin-top:12px;">
                                <div onclick="EditSaveItems()" class="button white_input save_input " style="width:55px; height:16px; float:left;margin-right:10px;"></div>  
                                <a class="button white" href="#" onclick="offpopupedit()"><span class="icon_text cancel"></span>Đóng</a> <!--Button Close-->
                                </div> 
                            </div>
                                                      
                    </div>
               
	    </div>                
    <div class="clear"></div>
    </div>    

<% } %>
<script type="text/javascript">
    function offpopupedit() {
        document.getElementById("popup_name").style.display = "none";
    }
</script>
</asp:Content>
